package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Others;
import org.hxyjs.entity.Others;
import org.hxyjs.entity.Others;
import org.hxyjs.entity.Others;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.OthersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 othersController
@RequestMapping("/othersController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /othersController
public class OthersController {
	@Resource
    OthersService othersService;
	@RequestMapping("/getAllOthers")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Others> getAllOthers() throws Exception{
    	System.out.println("查询全部第三方");
    	return othersService.getAllOtherss();
    }



	@RequestMapping("/deleteOthersByOno/{ono}")
	@ResponseBody
	public DTO<Others> deleteOthersByOno(@RequestBody @PathVariable("ono") String ono) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(ono+"删除第三方");
		return othersService.deleteOthersByOno(ono);
	}


	@RequestMapping("/updateOthersByOno")
	@ResponseBody
	public DTO<Others> updateOthersByOno(@RequestBody Others others) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改第三方成功");
		System.out.println(others);
		return othersService.updateOthersByOno(others);
	}

	@RequestMapping("/addOthersByOno")
	@ResponseBody
	public DTO<Others> addOthersByOno(@RequestBody Others others) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加第三方");
		return othersService.addOthersByOno(others);
	}

	@RequestMapping("/getOthersByOno/{ono}")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Others> getOthersByOno(@PathVariable("ono")String ono) throws Exception{
		System.out.println("根据主键查询全部第三方");
		return othersService.getOthersByOno(ono);
	}
	@RequestMapping("/getOthersByPage")
	@ResponseBody
	public DTO<Others> getOthersByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询第三方成功");
		return othersService.getOthersByPage(pageInfo);
	}

}
